package com.hanggold.springboot.lesson3.regx;

import java.io.*;
import java.util.Properties;

/**
 * @author smc
 * @date 2019-06-27 13:25
 * @since
 **/
public class TestOne {

    public static void main(String[] args) throws IOException {

        Properties properties = new Properties();


        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("regx.txt");


        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);


        BufferedReader bf = new BufferedReader(inputStreamReader);
        String regx = bf.readLine();

//       properties.load(inputStream);
//
//
//       String regx = String.valueOf(properties.get("content"));

//        System.out.printf("regx: %s \n", regx);
//
//        String tranfeRegx = tranfeRegx(regx);
//
//        System.out.println("tranfeRegx: "+ tranfeRegx);
////
////        String newRegx = regx.replaceAll("\\\\+","\\\\");
////
////        System.out.println("newRgex: "+ newRegx);
//
//        String content = "啊实打实木木时打卡哈撒大声地看哈萨科技的撒谎多久啊卡的很";
//
//        String newContent = content.replaceAll(tranfeRegx, "*");
//
//        System.out.println("new: " + newContent);



        String content = "s12{[(*asdasd";
        String newContent = "";
        for (int i = 0;i<content.length();i++){
            if (validateRegxChar(content.charAt(i))){
                newContent += "\\"+content.charAt(i);
            }else{
                newContent += content.charAt(i);
            }


        }

        System.out.println("n: "+ newContent);

    }


    public static String tranfeRegx(String regx){
        String[] fbsArr = { "\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|" };
        for (String key : fbsArr) {
            if (regx.contains(key)) {
                regx = regx.replace(key, "\\" + key);
            }
        }
        return regx;
    }

    private static  boolean validateRegxChar(char sensword){
        boolean validateRegx = false;

        char[] regxArr = { '\\', '$', '(', ')', '*', '+', '.', '[', ']', '?', '^', '{', '}', '|' };
        for (char regx : regxArr){
            if (sensword == regx){
                validateRegx = true;
                break;
            }
        }
        return validateRegx;
    }

}
